<?php
    @session_start();
    require_once 'shared-functions.php';
    require_once 'session.php';
    require_once 'masterpage.php';

    if(!IsValidSession())
    {
        header('Location: login.php?page=add-new-student');
        exit();
    }
    else
    {
        RefreshSession();
    }

	$user = GetCurrentUserAccessLevel();
	
    //Check user access
    if($user != $DIRECTOR && $user != $ADMIN && $user != $REGISTRAR)
    {
        header('Location: login.php?page=add-new-student&error=To access to the add new student page, please log in as a director, admin or registrar&logout=1');
        exit();
    }

    $link = connect_db();
    
    masterpage("Add New Student");
?>
    <link type="text/css" href="jquery/css/overcast/jquery-ui-1.8.9.custom.css" rel="stylesheet" />	
	<script type="text/javascript" src="jquery/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="jquery/js/jquery-ui-1.8.9.custom.min.js"></script>
	<script type="text/javascript">
		$(function(){

			// Datepicker1
			$('#datepicker1').datepicker({
				dateFormat: 'dd/mm/yy',
				width: '100px',
                changeYear: true,
                yearRange: "1900:" + new Date().getFullYear(),
				inline: true
			});
		
		});
	</script>
	<style type="text/css">
		div.ui-datepicker{ font-size:12px;}
	</style>
    <table class="DataList">
        <form action="create-new-student-db.php" method="post">
        <tr><th class="header" colspan="2">Add New Student</th></tr>
<?php 
	if(isset($_SESSION['login_error']))
	{
		echo "<tr><td align=\"center\" colspan=\"2\">" . $_SESSION['login_error'] ."</td></tr>";
		$_SESSION['login_error'] = "";
	}
?>
        <tr><td colspan="2"><center><font color="red">Marked fields are required</font></center></td></tr>
		<tr><td>School ID</td><td><input type="text" size="20" name="schoolid" /></td></tr>
        <tr><td>NMC ID</td><td><input type="text" size="20" name="nmcid" /></td></tr>
        <tr><td>First Name</td><td><input type="text" size="40" name="firstName" /><font color="red">*</font></td></tr>
        <tr><td>Middle Name</td><td><input type="text" size="40" name="middleName" /></td></tr>
        <tr><td>Last Name</td><td><input type="text" size="40" name="lastName" /><font color="red">*</font></td></tr>
        <tr><td>Phone Number</td><td><input type="text" size="40" name="phoneNumber" /></td></tr>
        <tr><td>Email Address</td><td><input type="text" size="40" name="emailAddress" /></td></tr>
        <tr><td>Address</td><td><input type="text" size="40" name="address" /></td></tr>
        <tr><td>City</td><td><input type="text" size="40" name="city" /></td></tr>
        <tr><td>Postal Code</td><td><input type="text" size="40" name="postalCode" /></td></tr>
        <tr><td>Hometown</td><td><input type="text" size="40" name="hometown" /></td></tr>
        <tr><td>Region</td><td><input type="text" size="40" name="region" /></td></tr>
        <tr><td>Country</td><td><input type="text" size="40" name="country" /></td></tr>
        <tr><td>Date of Birth</td><td><input type="text" id="datepicker1" size="40" name="dob" /><font color="red">*</font></td></tr>
        <tr><td>Sex</td><td><select name="sex">
            <option value="M">Male</option>
            <option value="F">Female</option>
            </select><font color="red">*</font></td></tr>
        <tr><td>Program</td><td><select name="program">
<?php
        $query = "SELECT `ProgramID`,`Name`,`Code`,`Year`,`Semester` FROM `Program`;";
        $result = mysql_query($query,$link);
        while($program=mysql_fetch_array($result,MYSQL_BOTH))
        {
            echo '<option value ="'.$program['ProgramID'].'">'.$program['Name'].', '.
                                                               $program['Code'].'-'.
                                                               str_pad($program['Semester'], 2, '0', STR_PAD_LEFT).'-'.
                                                               $program['Year'].'</option>';
        }
?>
        </select><font color="red">*</font></td></tr>
        <tr><td colspan="2"><input type="submit" value="Add" /></tr></tr>
        </table>
<?php
	endmasterpage();
?>

